package cn.orangeframe.neon.application.mapper;


import cn.orangeframe.neon.application.run.DeciderService;
import cn.orangeframe.neon.domain.entity.WorkflowDef;
import cn.orangeframe.neon.domain.entity.WorkflowTask;
import cn.orangeframe.neon.domain.model.TaskModel;
import cn.orangeframe.neon.domain.model.WorkflowModel;
import lombok.Builder;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
@Builder
public class TaskMapperContext {

    private String taskId;

    private WorkflowTask taskToSchedule;

    private WorkflowModel workflowInstance;

    private WorkflowDef workflowDefinition;

    private DeciderService deciderService;

    private int retryCount;

    private String retryTaskId;

    private Map<String, Object> taskInput;

    public TaskModel createTaskModel() {
        TaskModel taskModel = new TaskModel();
        taskModel.setTaskReferenceName(taskToSchedule.getTaskReferenceName());
        taskModel.setWorkflowInstanceId(workflowInstance.getWorkflowId());
        taskModel.setScheduledTime(System.currentTimeMillis());
        taskModel.setTaskId(taskId);
        taskModel.setWorkflowTask(taskToSchedule);

        // the following properties are overridden by some TaskMapper implementations
        taskModel.setTaskType(taskToSchedule.getType());
        taskModel.setInputData(new HashMap<>());
        taskModel.setOutputData(new HashMap<>());
        return taskModel;
    }
}
